<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 14. BSP toolkit</a><br />
<a href="bsp_traverse.html">&lt; 14.5 Traversing the tree</a>
</td><td width="60%">
<p align="center">
=====================================<br />
14.6 Destroying a tree<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
You can delete a part of the tree, releasing resources for all sub nodes with :<br />
<p class="code"><pre>
C++ : void TCODBsp::removeSons()
C   : void TCOD_bsp_remove_sons(TCOD_bsp_t *node)
Py  : bsp_remove_sons(node)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>node</td><td>In the C version, the node reference.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODBsp *myBSP = new TCODBsp(0,0,50,50);
      // create a tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
      // clear it (keep only the root)
      myBSP->removeSons();
      // and rebuild another random tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
C   : TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
      TCOD_bsp_remove_sons(my_bsp);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
Py  : my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
      libtcod.bsp_remove_sons(my_bsp)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
</pre></p>
<br />
You can also completely delete the tree, including the root node to release every resource used :<br />
<p class="code"><pre>
C++ : void TCODBsp::~TCODBsp()
C   : void TCOD_bsp_delete(TCOD_bsp_t *node)
Py  : bsp_delete(node)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>node</td><td>In the C version, the node reference.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODBsp *myBSP = new TCODBsp(0,0,50,50);
      // create a tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
      // use the tree ...
      // delete the tree
      delete myBSP; 
C   : TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
      /* use the tree ... */
      TCOD_bsp_delete(my_bsp);
Py  : my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
      # use the tree ...
      libtcod.bsp_delete(my_bsp)
</pre></p>

